/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "rs_render_process_manager.h"

#include "rs_render_composer_manager.h"
#include "rs_render_service.h"
#include "pipeline/main_thread/rs_main_thread.h"
#include "rs_render_pipeline.h"
#include "transaction/rs_service_to_render_connection.h"

#undef LOG_TAG
#define LOG_TAG "RSRenderProcessManager"

namespace OHOS {
namespace Rosen {
sptr<RSRenderProcessManager> RSRenderProcessManager::Create(RSRenderService& renderService)
{
    sptr<RSRenderProcessManager> renderProcessManager;
    if (renderService.renderModeConfig_->GetIsMultiProcessModeEnabled()) {
        RS_LOGI("dmulti_process multi process manager init");
        renderProcessManager = new RSMultiRenderProcessManager(renderService);
    } else {
        RS_LOGI("dmulti_process single process manager init");
        renderProcessManager = new RSSingleRenderProcessManager(renderService);
    }
    return renderProcessManager;
}

sptr<IRemoteObject> RSRenderProcessManager::OnScreenConnected(ScreenId id, const ScreenEventData& data, const RSScreenProperty& property)
{
    RS_LOGI("dmulti_process %{public}s: OnScreenConnected start", __func__);
    renderService_.rsRenderComposerManager_->OnScreenConnected(data.output, property);
    RS_LOGI("dmulti_process %{public}s: OnScreenConnected rsScreenProperty.id[%{public}lu] .width[%{public}d] .height[%{public}d]",
        __func__, property.GetScreenId(), property.GetWidth(), property.GetHeight());
    return nullptr;
}

void RSRenderProcessManager::OnScreenDisconnected(ScreenId id, const ScreenEventData& data)
{
    RS_LOGI("dmulti_process %{public}s: OnScreenDisconnected start", __func__);
    renderService_.rsRenderComposerManager_->OnScreenDisconnected(id);
}

void RSRenderProcessManager::OnScreenPropertyChanged(ScreenId id, const RSScreenProperty& property)
{
    RS_LOGI("dmulti_process %{public}s: OnScreenPropertyChanged start", __func__);
    // TODO: composer manager需要适配
    // renderService_.rsRenderComposerManager_->OnScreenPropertyChanged(data.output, proeprty);
}
} // namespace Rosen
} // namespace OHOS